<?php 
ini_set('display_errors','On');
date_default_timezone_set('Asia/Bangkok');
include '../puja.php';
$tpl = new Puja;
$tpl->template_dir = 'templates/';
$tpl->cache_dir = 'cache/';

// custom filter
class CustomFilter{
	/* {{ {var}|url:{arg} }} */
	function filter_urlize($var, $arg = null){
		$var = strtolower($var);
		$var = str_replace(' ','-',$var);
		$var = substr($var, 0, $arg);
		return $var;
	}
	/* {{ {var}|ext }} */
	function filter_ext($var, $arg = null){
		return substr($var,-4);
	}
}
// custom tags
class CustomTags{
	/* {% css_tag {val} %} */
	function css_tag($val, $arg = null){
		return '&lt;link src="'.$val.'" /&gt;';
	}
	/* {% js_tag {val} %} */
	function js_tag($val, $arg = null){
		return '&lt;script src="'.$val.'?'.$arg.'"&gt;&lt;/script&gt;';
	}
}

$tpl->cutom_tags = new CustomTags;
$tpl->cutom_filter= CustomFilter;
$dir = 'templates';
$array_file = array();
function struct($dir, &$array_file){
	if ($dh = opendir($dir)){
		while (($file = readdir($dh)) !== false){
			if($file != '.' && $file != '..'){
				if(is_dir($dir.'/'.$file)){
					struct($dir.'/'.$file,$array_file);
				}else{
					$array_file[] =  $file;
				}
				
			}
			
		}
		closedir($dh);
	}
	
}
struct($dir,$array_file);

foreach($array_file as $val){
	
	
	$tpl->parse($val,array(),true);
}
?>
